package common.model.entity;

import javax.swing.*;
import java.io.Serializable;

/**
 * 用户实体类
 */

public class User implements Serializable {
    private static final long serialVersionUID = 5942011574971970871L;
    private Long id;
    private String password;
    private String nickname;
    private int head;
    private String sex;

    public User() {}

    public User(String password, String nickname){
        this.password = password;
        if(nickname.equals(""))
        {
            this.nickname = "未命名";
        }else{
            this.nickname = nickname;
        }
    }

    public User(Long id, String password){
        this.id = id;
        this.password = password;
    }

    public User(String password, String nickname, String sex, int head){
        this.password = password;
        this.sex = sex;
        this.head = head;
        if(nickname.equals(""))
        {
            this.nickname = "未命名";
        }else{
            this.nickname = nickname;
        }
    }



    public Long getId(){
        return  id;
    }

    public void setId(Long id){
        this.id = id;
    }

    public void setPassword(String password){
        this.password = password;
    }

    public String getPassword(){
        return password;
    }

    public void setSex(String sex){
        this.sex=sex;
    }

    public String getSex(){
        return this.sex;
    }

    public void setNickname(String nickname){
        this.nickname = nickname;
    }

    public String getNickname(){
        return this.nickname;
    }

    public void setHead(int head){
        this.head = head;
    }

    public int getHead(){
        return this.head;
    }

    public ImageIcon getHeadIcon(){
        return new ImageIcon("images/"+head+".png");
    }

    @Override
    public boolean equals(Object obj) {
        if(this == obj)
            return true;
        if(obj == null)
            return false;
        if(getClass() != obj.getClass())
            return false;
        User other = (User) obj;
        if(head != other.head || !id.equals(other.id) || !sex.equals(other.sex))
            return false;
        if(nickname == null){
            if(other.nickname != null)
                return false;
        }else if(!nickname.equals(other.nickname))
            return false;
        if(password == null){
            return other.password == null;
        }else return password.equals(other.password);
    }

    @Override
    public String toString() {
        return this.getClass().getName()
                + "[id=" + this.id
                + ",pwd=" + this.password
                + ",nickname=" + this.nickname
                + ",head=" + this.head
                + ",sex=" + this.sex
                + "]";
    }
}
